﻿@{
    ViewBag.Title = "销售商详情";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Model
@using ZBJF.Warranty.Model.ViewModel.Sellers
@model ZBJF.Warranty.Model.Sellers
<ul class="nav nav-tabs">
    <li class="active"><a href="/Sellers/Detail/@id">销售商详情</a></li>
</ul>
<div>
    @Html.HiddenFor(m => m.ID)
    <table class="table table-responsive table-bordered table-hover">
        <tr>
            <th>销售商名称</th>
            <th>销售机构代码</th>
            <th>销售商类型</th>
            <th>所属机构</th>
        </tr>
        <tr>
            <td>@Html.DisplayFor(m => m.SellersName)</td>
            <td>@Html.DisplayFor(m => m.SellerCode)</td>
            <td>@Html.DisplayFor(m => m.SellersType1.SellerTypeName)</td>
            <td>
                <a id="sellerOrganizationId">机构详情</a>
            </td>
        </tr>
    </table>
</div>
<h4>已配置产品</h4>
<table class="table table-responsive table-bordered table-hover" id="sellerInsuranceProductsList">
    <thead>
        <tr>
            <th width="20">序号</th>
            <th width="80">保险产品名称</th>
            <th width="80">承保公司</th>
            <th width="80">承保公司分公司</th>
            <th width="80">零售价</th>
            <th width="100">经销商零售价</th>
            <th width="100">中保金服销售价</th>
            <th width="100">最大库存</th>
            <th width="100">限购数量</th>
            <th width="100">是否启用</th>
            <th width="80">操作</th>
        </tr>
    </thead>
    <tbody>
        @{
            var list = Model.SellerInsuranceProducts.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                var insruanceCompany = list[i].InsuranceCompanyID.HasValue ? list[i].InsuranceCompany : new InsuranceCompany();
                <tr>
                    <td>@(i + 1)</td>
                    <td>@list[i].ProductName</td>
                    <td>@insruanceCompany.ParentCompanyName</td>
                    <td>@insruanceCompany.CompanyName</td>
                    <td>@list[i].SaleRetailPrice</td>
                    <td>@list[i].InsuranceCompanyRetailPrice</td>
                    <td>@list[i].ZBJFSalePrice</td>
                    <td>@list[i].MaxSalesQty</td>
                    <td>@list[i].IdentityCardLimitQty</td>
                    <td>@(list[i].IsAvailable ? "生效中" : "已暂停")</td>
                    <td>
                        @{ var status = @list[i].IsAvailable ? "false" : "true"; }
                        <a onclick="UpdateStatus(@list[i].ID, @status, '/Sellers/UpdateSellerInsuranceProducts')" style="cursor: pointer;">@(list[i].IsAvailable ? "禁用" : "启用")</a>
                        <a onclick="Open(0, @list[i].ID)" style="cursor: pointer;" title="修改"><i class='icon-edit'></i></a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>
<div class="padding-l-10 cursor"><a href="javascript:void(0)" onclick="Open(@id, 0)">配置更多保险产品</a></div>
<h4>商户员工信息</h4>
<label class="Add-R">
    <a id="AddNewRole" class="btn btn-xs btn-primary" data-toggle="modal" href="" onclick="showEditSellerEmployee(0)" title="销售商员工">
        <i class="icon-plus-sign bigger-130"></i>
        添加销售商员工
    </a>
</label>
<table class="table table-responsive table-bordered table-hover">
    <thead>
        <tr>
            <th width="20">序号</th>
            <th width="50">姓名</th>
            <th width="80">证件号码</th>
            <th width="80">手机号</th>
            <th width="100">电子邮箱</th>
            <th width="100">当前状态</th>
            <th width="80">操作</th>
        </tr>
    </thead>
    @{
        var List1 = Model.SellerEmployee.ToList();
    }
    @for (int i = 0; i < List1.Count; i++)
    {
        <tr>
            <td>
                @(i + 1)
            </td>
            <td>
                @List1[i].UserName
            </td>
            <td>
                @List1[i].CertificateNO
            </td>
            <td>
                @List1[i].UserPhone
            </td>
            <td>
                @List1[i].Email
            </td>
            <td>
                @(List1[i].IsAvailable ? "生效中" : "已暂停")
            </td>
            <td>
                <a onclick="UpdateSellerEmployeeStatus(@(List1[i].IsAvailable ? "false" : "true"), @List1[i].ID, 0)" style="cursor: pointer;"><i class=@(List1[i].IsAvailable?"icon-remove":"icon-ok") title='@(List1[i].IsAvailable ? "禁用" : "启用")'></i></a>
                <a class='Edit-R' onclick="showEditSellerEmployee(@List1[i].ID)" title='编辑'><i class='icon-edit'></i></a>
                <a class="red edit-r" href="javascript:ShowResetPSWswDialog(@List1[i].ID)" title="重置密码"><i class="icon-refresh bigger-130"></i></a>
            </td>
        </tr>
    }
    <tbody></tbody>
</table>

<a style="cursor:pointer;" href='/Sellers/ExportSellerEmployee/@id' title='下载全部员工清单'>下载全部员工清单</a>
<a style="cursor:pointer;" onclick="UpdateSellerEmployeeStatus(false,0)" title='暂停所有员工权限'>暂停所有员工权限</a>
<a style="cursor: pointer;" onclick="UpdateSellerEmployeeStatus(true, 0)" title='恢复所有员工权限'>恢复所有员工权限</a>

<div style="text-align:center;margin-top:100px;">
    <input id="btnClose" class="btn btn-primary Edit-R" type="submit" value="关闭" onclick="javascript:location.href = '/Sellers/Index';" />
</div>
@section scripts{
    <script>
        window.onload = function() {
            $("#sellerOrganizationId").click(function() {
                layer.open({
                    type: 2,
                    title: '所属机构详情',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['320px', '60%'],
                    content: '/PubModelDialog/SellersOrganizationSelector?chkStyle=radio&ParentCategoryID=' + @Model.SellersOrganizationId+'&Type=1'//单选
                });
            });
        }
        function UpdateSellerEmployeeStatus(staus, id, type) {
            var herf = "/Sellers/UpdateSellerEmployee";
            $.ajax({
                url: herf + "?SellerID=" + @id,
                type: "post",
                data: {
                    "ID": id,
                    "IsAvailable": staus
                },
                dataType: "json",
                success: function(data) {
                    if (data.success) {
                        layer.alert(data.message, function() {
                            layer.load(1);
                            location.href = '/Sellers/Detail/@id';
                        });
                    } else {
                        layer.alert(data.message);
                    }
                }
            });
        }

        function Open(sellerId, sellerInsuranceProductsId) {
            layer.open({
                type: 2,
                title: '添加商家保险产品',
                shade: 0.8,
                area: ['80%', '80%'],
                content: '/SellerInsuranceProducts/Edit?sellerId=' + sellerId + '&&sellerInsuranceProductsId=' + sellerInsuranceProductsId //iframe的url
            });
        }

        ///重置
        function RestPassWord(id, password) {
            $.ajax({
                type: "post",
                data: { id: id, newPassWord: password },
                url: "/Sellers/RestPassWord",
                success: function(result) {
                    if (result.success) {
                        var index = layer.alert(result.message, {
                            yes: function() {
                                layer.close(index);
                            }
                        });
                    } else {
                        layer.alert(result.message);
                    }
                }
            });
        }

        function ShowResetPSWswDialog(id) {
            layer.prompt("请输入新的密码", function(result) {
                if (result == null) {
                    layer.alert("请输入密码！");
                } else if (result == "" || result.length < 6) {
                    var index = layer.alert(result.message, {
                        yes: function() {
                            layer.alert("请输入密码长度不能小于六位!");
                        }
                    });
                } else {
                    RestPassWord(id, result);
                }
            });
        }

        function showEditSellerEmployee(id) {
            var sellerId = $("#ID").val();
            var chilIds = $("#main").children().children().children().siblings();
            layer.open({
                type: 2,
                title: '销售商员工信息',
                shade: 0.8,
                area: ['600px', '500px'],
                content: '/SellerEmployee/Detail?id=' + id + '&sellerId=' + sellerId //iframe的url
            });
        }
    </script>
}